gsk: add a has_color boolean to text nodes
authorMatthias Clasen <mclasen@redhat.com>
Sat, 2 Sep 2017 15:06:20 +0000 (11:06 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 2 Sep 2017 15:09:03 +0000 (11:09 -0400)
Currently, this information is not used since cairo_show_glyphs
deals with color glyphs for us. But when we get to uploading
glyphs to a texture atlas, we will need it to do the right thing.

We don't look at individual glyphs here, but just whether the
font has the has-color flag set. In practice, all glyphs in
such a font will be color glyphs, and we can avoid loading all
the glyphs this way.

gsk/gskrendernodeimpl.c

index 2d04bb3a64c2258a2de2c4012abadffbf8bb6572..0b0981efe4040bd75ebcc9208270c0b6585a8488 100644 (file)
@@ -26,6 +26,8 @@
 #include "gskroundedrectprivate.h"
 #include "gsktextureprivate.h"
 
+#include <cairo-ft.h>
+
 static gboolean
 check_variant_type (GVariant *variant,
                     const char *type_string,
@@ -3810,6 +3812,7 @@ struct _GskTextNode
   GskRenderNode render_node;
 
   PangoFont *font;
+  gboolean has_color;
   PangoGlyphString *glyphs;
   GdkRGBA color;
   int x_offset;
@@ -4009,6 +4012,23 @@ static const GskRenderNodeClass GSK_TEXT_NODE_CLASS = {
   gsk_text_node_deserialize
 };
 
+static gboolean
+font_has_color_glyphs (PangoFont *font)
+{
+  cairo_scaled_font_t *scaled_font;
+  gboolean has_color = FALSE;
+
+  scaled_font = pango_cairo_font_get_scaled_font ((PangoCairoFont *)font);
+  if (cairo_scaled_font_get_type (scaled_font) == CAIRO_FONT_TYPE_FT)
+    {
+      FT_Face ft_face = cairo_ft_scaled_font_lock_face (scaled_font);
+      has_color = (FT_HAS_COLOR (ft_face) != 0);
+      cairo_ft_scaled_font_unlock_face (scaled_font);
+    }
+
+  return has_color;
+}
+
 GskRenderNode *
 gsk_text_node_new (PangoFont        *font,
                    PangoGlyphString *glyphs,
@@ -4031,6 +4051,8 @@ gsk_text_node_new (PangoFont        *font,
   self->base_x = base_x;
   self->base_y = base_y;
 
+  self->has_color = font_has_color_glyphs (font);
+
   pango_glyph_string_extents (glyphs, font, &ink_rect, NULL);
   pango_extents_to_pixels (&ink_rect, NULL);